package com.fa.controller;

import com.fa.entity.Clazz;
import com.fa.service.ClazzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Clazz)表控制层
 *
 * @author FA
 * @since 2020-09-16 10:09:15
 */
@Api(tags = " ClazzController操作接口")
@RestController
@RequestMapping("clazz")
public class ClazzController {
    /**
     * 服务对象
     */
    @Resource
    private ClazzService clazzService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "查询单条数据", httpMethod = "GET", notes = "返回单条数据")
    @GetMapping("selectOne")
    public Clazz selectOne(@ApiParam(name = "id", value = "id", required = true) @RequestParam("id") Integer id) {
        return this.clazzService.queryById(id);
    }


    /**
     * 动态询所有数据，不分页
     *
     * @param clazz
     * @return
     */
    @ApiOperation(value = "动态查询所有数据", httpMethod = "GET", notes = "动态条件查询所有数据，不分页")
    @GetMapping("queryAll")
    public List<Clazz> queryAll(Clazz clazz) {
        return this.clazzService.queryAll(clazz);
    }

    /**
     * 查询所有数据，分页
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return
     */
    @ApiOperation(value = "分页查询所有数据", httpMethod = "GET", notes = "无条件查询所有数据，分页")
    @GetMapping("queryAllByLimit")
    public List<Clazz> queryAllByLimit(@ApiParam(name = "offset", value = "查询起始位置", required = true) @RequestParam("offset") int offset, @ApiParam(name = "limit", value = "查询条数", required = true) @RequestParam("limit") int limit) {
        return this.clazzService.queryAllByLimit(offset, limit);
    }

    /**
     * 动态更新数据
     *
     * @param clazz
     * @return
     */
    @ApiOperation(value = "动态更新所有数据", httpMethod = "POST", notes = "注意时间的填写格式")
    @PostMapping("update")
    public Clazz update(@ApiParam(name = "对象", value = "传入json格式", required = false) @RequestBody Clazz clazz) {
        return this.clazzService.update(clazz);
    }


    /**
     * 删除单条数据
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除单条数据", httpMethod = "POST", notes = "只返回成功与否,true代表成功，false代表失败")
    @PostMapping("deleteById")
    public boolean deleteById(@ApiParam(name = "id", value = "填入要删除的id", required = true) @RequestParam("id") Integer id) {
        return this.clazzService.deleteById(id);
    }

    /**
     * 删除多条数据
     *
     * @param ids
     * @return object, 显示多少即为删除多少条
     */
    @ApiOperation(value = "删除多条数据", httpMethod = "POST", notes = "返回多少即为删除多少条")
    @PostMapping("deleteByIds")
    public Object deleteByIds(@ApiParam(name = "ids", value = "填入要删除的ids", required = true) @RequestParam("ids") List<Integer> ids) {
        return this.clazzService.deleteByIds(ids);
    }

    /**
     * 新增数据
     *
     * @param clazz 实例对象
     * @return 实例对象
     */
    @ApiOperation(value = "新增数据", httpMethod = "POST", notes = "如果插入失败则返回空值，成功则返回插入实体，更新人系统默认无")
    @PostMapping("insert")
    public Clazz insert(@ApiParam(name = "对象", value = "传入json ,Id为自动递增无法手动", required = false) @RequestBody Clazz clazz) {
        return this.clazzService.insert(clazz);
    }
}